package com.fauks.ssm.springmvc.annotation;

import com.fauks.ssm.springmvc.exception.NameException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/exception")
public class ExceptionController {

    @RequestMapping("/redirect")
    @ResponseBody
    public String testRedirect() {
        return "hello";
    }

    //遇到NameException使用该方法处理错误
    @ExceptionHandler(NameException.class)
    public ModelAndView handleEx(Exception ex) {
        //do something
        return new ModelAndView();
    }
}
